<template>
  <div>
    <h1>注册</h1>
    <table class="table table-bordered">
      <tr>
        <td>账号</td>
        <td><input type="text" v-model="state.userName" /></td>
      </tr>
      <tr>
        <td>密码</td>
        <td><input type="password" v-model="state.userPwd" /></td>
      </tr>
      <tr>
        <td></td>
        <td><input type="button" value="注册" @click="zhu" /></td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';
const router = useRouter();
const route = useRoute();

let data = reactive({
  state: {
    userName: '',
    userPwd: ''
  }
});

let { state } = toRefs(data);

const zhu = () => {
  axios({
    url: '/api/Users/PostZhuCe',
    method: 'post',
    data: state.value
  }).then((res) => {
    if (res.data.data == -1) {
      alert('该用户已存在');
      return;
    } else {
      alert('注册成功');
      router.push('/login');
    }
  });
};
</script>

<style scoped></style>
